package cn.kgc.controller;
import cn.kgc.pojo.User;
import cn.kgc.service.UserService;
import com.google.gson.Gson;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

import static jdk.nashorn.internal.objects.Global.print;

@Controller
public class UserController {
    @Resource
    private UserService userServiceImpl;

    public UserService getUserServiceImpl() {
        return userServiceImpl;
    }

    public void setUserServiceImpl(UserService userServiceImpl) {
        this.userServiceImpl = userServiceImpl;
    }

    @RequestMapping("/login.do")
    public String login(User user, Model model, HttpServletRequest request, HttpServletResponse response) throws IOException {
     User login = userServiceImpl.login(user);
        if (login != null) {
            //登录成功跳转 list 页面
            System.out.println("成功");
            model.addAttribute("login", "登录成功");
        } else {
//            登录失败跳回登录页面
            model.addAttribute("login", "用户名或密码不正确");
        }
        return "list";
    }
}
